package com.example.dao.impl;

import com.example.dao.ExtraDao;
import com.example.entity.customerAdmin.Extra;
import com.example.utils.BaseDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ExtraDaoImpl implements ExtraDao {

    @Override
    public List<Extra> selectById(int id) {
        List<Extra>extraList=new ArrayList<>();
        Object[]objects=new Object[1];
        objects[0]=id;
        ResultSet resultSet = BaseDao.select("select *from extre where cusid=?", objects);
        try {
            while (resultSet.next()){
                Extra extra=new Extra();
                extra.setId(resultSet.getInt("id"));
                extra.setArea(resultSet.getString("area"));
                extra.setAddress(resultSet.getString("address"));
                extra.setScale(resultSet.getString("scale"));
                extra.setCusId(resultSet.getInt("cusid"));
                extra.setRmkTip(resultSet.getString("rmk_tip"));
                extraList.add(extra);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return extraList;
    }

    @Override
    public int add(Extra extra) {
        Object[]objects=new Object[5];
        objects[0]=extra.getArea();
        objects[1]=extra.getAddress();
        objects[2]=extra.getScale();
        objects[3]=extra.getCusId();
        objects[4]=extra.getRmkTip();
        return BaseDao.modify("insert into extre(area,address,scale,cusid,rmk_tip)values(?,?,?,?,?)", objects);
    }
}
